<extend name="./public/frame.html"/>
<block name="content">
	<blockquote class="layui-elem-quote search">
		<div class="layui-inline">
			<input type="text" name="activity_name" id="activity_name" placeholder="活动名称" class="layui-input">
		</div>
		<div class="layui-inline">
			<input type="text" class="layui-input" id="start_time" placeholder="活动开始时间">
		</div>
		<div class="layui-inline">
			<input type="text" class="layui-input" id="end_time" placeholder="活动结束时间">
		</div>
		<div class="layui-inline">
			<select id="activity_model" name="activity_model" class="layui-input"lay-filter="activity_model" style="width: 150px;">
				<option value="">活动类型</option>
				<?php foreach($acitivetyType as $key=>$value):?>
				<option value="<?php echo $key;?>"><?php echo $value;?></option>
				<?php endforeach;?>
			</select>
		</div>
		<div class="layui-inline">
			<select id="status" name="status" class="layui-input" lay-filter="status" style="width: 150px;">
				<option value="">活动状态</option>
				<option value="0">未开始</option>
				<option value="1">进行中</option>
				<option value="2">已结束</option>
			</select>
		</div>
		<div class="layui-inline">
			<select id="order_type" name="order_type" class="layui-input"lay-filter="order_type" style="width: 120px;">
				<option value="">所属活动</option>
				<?php foreach($order_type as $key=>$value):?>
				<option value="<?php echo $key;?>"><?php echo $value;?></option>
				<?php endforeach;?>
				<option value="0">不限</option>
			</select>
		</div>

		<div class="layui-inline">
			<button class="layui-btn" data-type="search">搜索</button>
			<button class="layui-btn layui-btn-normal" data-url="{:url('add')}" onclick="add_t(this,'添加活动')">
				添加活动
			</button>
			<button class="layui-btn layui-btn-warm" data-url="{:url('look')}" onclick="add_t(this,'活动数据')">
				活动数据
			</button>
			<a href="{:url('AdminActivity/couponList')}" class="layui-btn layui-btn-normal">优惠券列表</a>
		</div>
	</blockquote>
	<table class="layui-table" lay-data="{width:'auto', height:'auto', url:'{:url('AdminActivity/index')}', page: true, limit: 10, id:'AdminActivity'}" lay-filter="AdminActivity">
		<thead>
		<tr>
			<th lay-data="{field:'id', width:70,fixed: true, sort: true,align:'center',fixed: true}">ID</th>
			<th lay-data="{field:'activity_name', width:180,align:'center'}">活动名称</th>
			<th lay-data="{field:'user_type', width:80,align:'center'}">活动对象</th>
			<th lay-data="{field:'activity_model', width:150,align:'center'}">活动类型</th>
			<th lay-data="{field:'user_type', width:80,align:'center'}">奖励类型</th>
			<th lay-data="{field:'order_type', width:100,align:'center'}">所属活动</th>
			<th lay-data="{field:'start_time', width:120,align:'center'}">活动开始时间</th>
			<th lay-data="{field:'end_time', width:120,align:'center'}">活动结束时间</th>
			<th lay-data="{field:'region_name', width:100,align:'center'}">城市</th>
			<th lay-data="{field:'rewardMoney', width:100,align:'center'}">金额 / 积分</th>
			<th lay-data="{field:'rewardNumber', width:100,align:'center'}">奖励人数</th>
			<th lay-data="{field:'admin_name', width:80,align:'center'}">添加人</th>
            <th lay-data="{field:'audit_status', width:100,align:'center'}">审核状态</th>
			<th lay-data="{field:'add_time', width:160,align:'center'}">时间</th>
			<th lay-data="{fixed:'right', toolbar: '#barDemo', width:300, align:'center'}">操作</th>
		</tr>
		</thead>
	</table>
	<script type="text/html" id="barDemo">
		<a class="layui-btn layui-btn-xs" lay-event="edit" style="width: 70px">修改/查看</a>
		<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del" style="width: 50px">删除</a>
		{{#  if(d.award_type == 2){ }}
		<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="coupon" style="width: 50px">优惠券</a>
		{{#  } }}
		{{#  if(d.award_type == 1 || d.activity_type ==2){ }}
		<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="supply" style="width: 40px">补 发</a>
		{{#  } }}
        <?php if($admin_info['admin_type'] == 1){ ?>
        <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="activity_audit" style="width: 50px">审核</a>
        <?php } ?>
	</script>
	<script>
		// && d.activity_type !=2
		layui.use(['form','table','laydate'], function () {
			var table = layui.table,form = layui.form,laydate = layui.laydate;
			laydate.render({
				elem: '#start_time' //指定元素
			});

			laydate.render({
				elem: '#end_time' //指定元素
			});
			table.on('tool(AdminActivity)', function (obj) {
				var data = obj.data;
				var id = data.id;
				if (obj.event === 'edit') {
					layer.open({
						type: 2,
						title: '编辑活动',
						shadeClose: true,
						shade: 0.8,
						area: ['100%', '100%'],
						content: '{:url("/admin/AdminActivity/edit","id=")}' + id //iframe的url
					});
				}else if (obj.event === 'del') {
					layer.confirm('确定删除吗?',function(index){
						var url = '{:url("/admin/AdminActivity/del","id=")}' + id
						$.get(url,function(data){
							if(data.status == 1){
								layer.msg(data.msg,{'icon':1});
								window.location.reload();
							}else{
								layer.msg(data.msg,{'icon':2});
							}
						},'json')
						layer.close(index);
					})
				}else if (obj.event === 'coupon') {
					layer.open({
						type: 2,
						title: '优惠券列表',
						shadeClose: true,
						shade: 0.8,
						area: ['100%', '100%'],
						content: '{:url("/admin/AdminActivity/couponList","admin_activity_id=")}' + id //iframe的url
					});
				}else if (obj.event === 'activity_audit') {
                    layer.confirm('确定审核通过吗?', function (index) {
                        var url = "{:U('activity_audit')}";
                        $.post(url, {'activity_id': id}, function (data) {
                            console.log(data);
                            if(data.status == 1){
                                layer.msg(data.msg,{'icon':1});
                                window.location.reload();
                            }else{
                                layer.msg(data.msg,{'icon':2});
                            }
                        }, 'json');
                        layer.close(index);
                        window.location.reload();
                    });
                }else if (obj.event === 'supply') {
					$.ajax({
						url:'{:url("/admin/AdminActivity/supplyMoney")}',
						async:true,
						dataType:'json',
						type:'post',
						data: {'id':id},
						success:function(res){
							if(res.code==1){
								layer.open({
									type: 2,
									title: '补发活动金额',
									shadeClose: true,
									shade: 0.8,
									area: ['90%', '90%'],
									content: '{:url("/admin/admin_activity/supplyMoney","id=")}' + id //iframe的url
								});
							}else{
								layer.msg(res.msg,{icon: 5});
							}
						}
					});
				}
			});

			//搜索
			$('.layui-btn').on('click', function () {
				var activity_name 	= $("#activity_name").val();
				var start_time 		= $("#start_time").val();
				var end_time 		= $("#end_time").val();
				var order_type		= $("#order_type").val();
				var user_type		= 1;
				var activity_model		= $("#activity_model").val();
				var status		= $("#status").val();

				table.reload('AdminActivity', {
					url: '/admin/AdminActivity/index', where: {
						"activity_name": activity_name,
						"start_time": start_time,
						"end_time": end_time,
						"order_type": order_type,
						"user_type": user_type,
						"activity_model": activity_model,
						"status": status,

					}
				});
			});
		});
	</script>
</block>
